package utils;

import java.util.HashMap;
import java.util.Map;

public class CalculatorFactory {
	
	public static String AVERAGE_LINK="A";
	public static String COMPLETE_LINK="C";
	public static String SINGLE_LINK="S";
	
	public static String EUCLIDEAN="E";
	public static String MANHATTAN="M";
	
	private static Map<String, ClusterDistanceCalculator> clusterDistanceCalculators;
	private static ClusterDistanceCalculator currentCalculator;
	
	public CalculatorFactory() {
		initCalculators();
	}
	
	public static ClusterDistanceCalculator getClusterDistanceCalculator(String clusterDCType, String GeneDCType) {
		currentCalculator =clusterDistanceCalculators.get(clusterDCType+GeneDCType); 
		return currentCalculator;
	}
	
	public static void reset() {
		initCalculators();
	}
	
	private static void initCalculators() {
		clusterDistanceCalculators = new HashMap<String, ClusterDistanceCalculator>(6);
		EuclideanDistance e=new EuclideanDistance();
		Manhattan m=new Manhattan();
		ClusterDistanceCalculator c;
		c=new AverageLink();
		c.setGeneDistanceCalculator(e);
		clusterDistanceCalculators.put(AVERAGE_LINK+EUCLIDEAN , c);
		c=new AverageLink();
		c.setGeneDistanceCalculator(m);
		clusterDistanceCalculators.put(AVERAGE_LINK+MANHATTAN , c);
		
		c=new CompleteLink();
		c.setGeneDistanceCalculator(e);
		clusterDistanceCalculators.put(COMPLETE_LINK+EUCLIDEAN , c);
		c=new CompleteLink();
		c.setGeneDistanceCalculator(m);
		clusterDistanceCalculators.put(COMPLETE_LINK+MANHATTAN , c);

		c=new SingleLink();
		c.setGeneDistanceCalculator(e);
		clusterDistanceCalculators.put(SINGLE_LINK+EUCLIDEAN , c);
		c=new SingleLink();
		c.setGeneDistanceCalculator(m);
		clusterDistanceCalculators.put(SINGLE_LINK+MANHATTAN , c);
	}
}
